using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace MobileEditor
{
	public partial class PathExplorerForm : Form
	{
		public PathExplorerForm()
		{
			InitializeComponent();
		}

		public string SelectedPath
		{
			get { return (tvPath.SelectedNode == null ? "" : tvPath.SelectedNode.Tag.ToString()); }
		}

		private void PathExplorerForm_Load(object sender, EventArgs e)
		{
			TreeNode node = tvPath.Nodes.Add(@"\");
			node.Nodes.Add("Loading...");
			node.Tag = @"\";
			node.Expand();
		}

		private void tvPath_AfterExpand(object sender, TreeViewEventArgs e)
		{
			tvPath.BeginUpdate();
			try
			{
				e.Node.Nodes.Clear();
				List<string> subDirectories = new List<string>(Directory.GetDirectories(e.Node.Tag.ToString()));
				subDirectories.Sort();
				foreach (string subDirectory in subDirectories)
				{
					TreeNode node = e.Node.Nodes.Add(Path.GetFileName(subDirectory));
					node.Tag = subDirectory;
					node.Nodes.Add("Loading...");
				}
			}
			finally
			{
				tvPath.EndUpdate();
			}
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			DialogResult = DialogResult.OK;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			DialogResult = DialogResult.Cancel;
		}
	}
}